import Router from '@koa/router';
import RoleController from '@/controllers/RoleController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/roles',
});

/**
 * 角色路由
 */

// 获取角色列表
router.get('/', auth, requirePermission('role', PermissionAction.READ), RoleController.list.bind(RoleController));

// 获取角色详情
router.get('/:id', auth, requirePermission('role', PermissionAction.READ), RoleController.detail.bind(RoleController));

// 创建角色
router.post('/', auth, requirePermission('role', PermissionAction.CREATE), RoleController.create.bind(RoleController));

// 更新角色
router.put('/:id', auth, requirePermission('role', PermissionAction.UPDATE), RoleController.update.bind(RoleController));

// 删除角色
router.delete('/:id', auth, requirePermission('role', PermissionAction.DELETE), RoleController.delete.bind(RoleController));

// 获取角色权限
router.get('/:id/permissions', auth, requirePermission('role', PermissionAction.READ), RoleController.getPermissions.bind(RoleController));

// 分配权限
router.post('/:id/permissions', auth, requirePermission('role', PermissionAction.MANAGE), RoleController.assignPermissions.bind(RoleController));

export default router;

